package com.youchuang.action.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.Category;
import com.youchuang.common.Constant;
import com.youchuang.service.MainService;

import net.sf.json.JSONObject;

/**
 * 大目录的查询
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/admin")
@ParentPackage("shopping-default")
public class CategoryListAction extends BaseAction {
	private static Logger logger = Logger.getLogger(CategoryListAction.class.getSimpleName());
	private JSONObject resultObj;
	@Resource
	private MainService mainService;

	@Action(value = "categoryList", results = {
			@Result(name = Constant.SUCCESS, type = "json", params = { "root", "resultObj" }) })
	public String execute() throws Exception {
		logger.info("method is execute");
		List<Category> categories = mainService.findCategoryByAll();
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		jsonMap.put(Constant.ROWS, categories);
		resultObj = JSONObject.fromObject(jsonMap);
		logger.info("response json resultObj = " + resultObj.toString());
		return Constant.SUCCESS;
	}

	public JSONObject getResultObj() {
		return resultObj;
	}

	public void setResultObj(JSONObject resultObj) {
		this.resultObj = resultObj;
	}

}
